import { DbService } from '@app/db';
import { Member } from '@app/db/common/entities/Member';
import { Menu } from '@app/db/common/entities/Menu';
import { I18nService } from '@app/i18n';
import { Injectable } from '@nestjs/common';
import { AuthService } from 'apps/admin/src/common/auth/auth.service';

@Injectable()
export class AppService {
  constructor(
    private readonly db:DbService,
    private readonly auth:AuthService
  ){}

  async init() {
    const time = Math.floor((new Date()).getTime() / 1000)

    const salt = this.auth.generateSalt()
    this.db.member.insert({
      account : 'admin',
      password : this.auth.buildPassword('123456', salt),
      salt : salt,
      belong : 0,
      super : true,
      remark : '超级管理员',
      registerTime : time
    })

    

    const systemFold:{[key in keyof Menu]? : Menu[key]} = {
      name : 'SYS_MANAGE',
      type : 'FOLD',
      path : '/system',
      permission : 'system',
      display : true,
    }
    const systemFoldRes = await this.db.menu.insert(systemFold)

    const menuPage:{[key in keyof Menu]? : Menu[key]} = {
      name : 'MENU_MANAGE',
      type : 'PAGE',
      path : 'menu',
      permission : 'system:menu',
      display : true,
      parentId : systemFoldRes.rows[0].id
    }
  }

  getHello(): string {
    
    return 'Hello World!';
  }
}
